//
//  BRInfoAvatorCell.m
//  FD
//
//  Created by Yasin on 2018/10/17.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "BRInfoAvatorCell.h"
@interface BRInfoAvatorCell()
/**nameLb*/
@property (nonatomic,  strong) UILabel *nameLb;
@end

@implementation BRInfoAvatorCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setuView];
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        //给contentView添加点击事件
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAvatorGesAction:)];
        [self.contentView addGestureRecognizer:tap];
    }
    return self;
}

- (void)setFrame:(CGRect)frame {
    frame.size.height -= 1;
    
    [super setFrame:frame];
}

- (void) setuView
{
    [self.contentView addSubview:self.nameLb];
    [self.contentView addSubview:self.iconIv];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(20);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(100, 25));
    }];
    [self.iconIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
}
- (UILabel *)nameLb {
    if (!_nameLb) {
        _nameLb = [[UILabel alloc] init];
        
        //国际化
        NSString *txStr = NSLocalizedString(HeadPortrait, @"头像");
        _nameLb.text = txStr;

        _nameLb.backgroundColor = [UIColor clearColor];
        _nameLb.textColor = BR_RGB_HEX(0x464646, 1.0);
        _nameLb.font = [UIFont systemFontOfSize:16.0f * kScaleFit];
        _nameLb.textAlignment = NSTextAlignmentLeft;
    }
    return _nameLb;
}
- (UIImageView *)iconIv {
    if (!_iconIv) {
        _iconIv = [[UIImageView alloc] init];
        //坑死了。UIImageView切圆角不给颜色会导致图片变形。❌
        _iconIv.backgroundColor = [UIColor whiteColor];
        _iconIv.layer.masksToBounds = YES;
        _iconIv.layer.cornerRadius = 25;
        
        //给cell添加手势
        _iconIv.userInteractionEnabled = YES; //打开交互
    }
    return _iconIv;
}

#pragma mark - 点击事件
- (void)tapAvatorGesAction:(UITapGestureRecognizer *)tap
{
    if ([self.delegate respondsToSelector:@selector(brInfoAvatorCellDidClockAvaorAction:)]) {
        [self.delegate brInfoAvatorCellDidClockAvaorAction:self.iconIv];
    }
}


@end
